package com.gwd.task.model;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.gwd.task.entity.TestEntity;
import com.gwd.task.group.GroupUpdate;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zhiyongming
 * @date 2020/12/24 15:09
 */
@Data
@NoArgsConstructor
public class TestDTO {
    private String groupName;
    private String projectName;
    private String lv1ModuleName;
    private String lv2ModuleName;
    private String respPersonName;
    private String devPersonName;
    private String testPersonName;
    private String codeRepositoryName;
    private String[] module;
    private String describe;
    @NotBlank(message = "临时编号不能为空", groups = {GroupUpdate.class})
    private String tempCode;
    private Long taskId;
    private String taskName;
    private String task_decomposition;
    private String task_describe;
    private String preRepair;
    private String preOnline;
    private Boolean noClose;
    private Boolean noRefuse;
    private Integer isBack;
    @NotNull(message = "测试id不能为空", groups = {GroupUpdate.class})
    private Long tId;
    private Long test_id;
    @NotNull(message = "组别不能为空")
    private Long groupId;
    private Long crId;
    private Long projectId;
    private String testCode;
    // 测试类型 0:任务、1:生产、2:测试 3:回归测试 与CodeSubmitRecordEntity csr_type一致
    private Integer type;
    // 测试状态: 0:新建|1:已指派|2:打开|3:代码已上传|4:待测试|5:已关闭|6:再次打开|7:拒绝|8:待自测
    private Integer status;
    // 问题类型 0：样式bug|1:程序bug|2:接口问题|3:页面优化|5:未知
    private Integer questionType;
    private String questionTypeName;
    // 得分
    private Integer score;
    //模块id
    private Long lv1ModuleId;
    //模块id
    private Long lv2ModuleId;
    //关联的id 用于任务及生产
    private Long relateId;
    //发现时间
    private String findTime;
    //分配时间
    private String dispatchTime;
    //开发时间
    private String openTime;
    //代码提交时间
    private String submitTime;
    //关闭时间
    private String closeTime;
    //责任人
    private Long respPerson;
    //开发负责人
    private Long devPerson;
    //测试负责人
    private Long testPerson;

    private List<AttachmentDTO> attachments;

    public void addAttachment(AttachmentDTO dto) {
        if (this.attachments==null) {
            this.attachments = new ArrayList<>();
        }
        this.attachments.add(dto);
    }

    public TestDTO (TestEntity entity) {
        BeanUtil.copyProperties(entity, this, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(false));
    }

    public String getStatusName() {
        // 0:新建|1:已指派|2:打开|3:代码已上传|4:待测试|5:已关闭|6:再次打开|7:拒绝
        switch (this.status) {
            case 0:
                return "新建";
            case 1:
                return "已指派";
            case 2:
                return "打开";
            case 3:
                return "代码已上传";
            case 4:
                return "待测试";
            case 5:
                return "已关闭";
            case 6:
                return "再次打开";
            case 7:
                return "拒绝";
        }
        return "";
    }

    public String getTypeName() {
        // 测试类型 0:任务、1:生产、2:测试 与CodeSubmitRecordEntity csr_type一致
        switch (this.type) {
            case 0:
                return "任务";
            case 1:
                return "生产";
            case 2:
                return "测试";
            case 3:
                return "回归";
        }
        return "";
    }

    public String getQuestionTypeName() {
        if (this.questionType ==null) return "";
        switch (this.questionType) {
            case 0:
                return "样式bug";
            case 1:
                return "程序bug";
            case 2:
                return "接口问题";
            case 3:
                return "页面优化";
            case 4:
                return "未知";
        }
        return "";
    }
}
